package com.vecspace.dayu.code.template.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.vecspace.database.dao.BaseDao;
import com.vecspace.dayu.code.template.pojo.TemplatePageLayout;

/** 页面布局类型,操作数据库的dao类
 * @author: wanghua
 */
@Repository("dayu_templatePageLayoutDao")
public class TemplatePageLayoutDao extends BaseDao {
	/** 根据ID查询 页面布局类型
	 * @param id   主键值
	 * @return TemplatePageLayout
	 * @throws Exception
	 * @author wanghua
	 */
	public TemplatePageLayout getTemplatePageLayout(Long id) throws Exception {
		TemplatePageLayout templatePageLayout = null;
		if (id != null && id != 0) {

			templatePageLayout = this.queryObject(TemplatePageLayout.class, id);
			this.evict(templatePageLayout);
		}
		return templatePageLayout;
	}
	
	public List<TemplatePageLayout> getTemplatePageLayouts(String terminalType) throws Exception {
		List<TemplatePageLayout> layouts = this.queryObjectList("from TemplatePageLayout where terminalType=?0 order by ordnum", new Object[] {terminalType});
		this.evict(layouts);
		return layouts;
	}

	/** 插入或修改 页面布局类型 
	 * @param item	要保存的对象
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void saveTemplatePageLayout(TemplatePageLayout item) throws Exception {
		boolean addFlag = item.getId() == null;
		this.saveOrUpdateObject(item);
		this.evict(item);
		if(addFlag){
			this.onAddDataRow("DAYU_CODE_TEMPLATE_PAGE_LAYOUT", item);
		}else{
			this.onUpdateDataRow("DAYU_CODE_TEMPLATE_PAGE_LAYOUT", item);
		}
	}

	/** 根据ID删除 页面布局类型 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void deleteTemplatePageLayout(Long id) throws Exception {
		if (id != null && id != 0) {
			this.deleteObject(TemplatePageLayout.class, id);
			this.onDeleteDataRow("DAYU_CODE_TEMPLATE_PAGE_LAYOUT",id);
		}
	}
}
